
window.onload = function () {
    // 取消搜索框绑定

    
    // 定位到homepage
    openHomepage();
    
    // 搜索框重新绑定
    
    // 导航栏事件绑定
    document.querySelectorAll(".navbar-item").forEach((tab, i, nodes) => {
        let tab_name = tab.getAttribute("name");
        tab.onclick = function() {
            navRelocation(tab_name);
            if(name === "homepage") {
                openHomepage();
            }
            if(name === "video-dataset") {
                openVideoDataset();
            }
        };
    });
    
}

function navRelocation(name) {
    name = name || "homepage";
    console.log(name + "tab clicked.");

    document.querySelectorAll(".navbar-item").forEach((tab, i, nodes) => {
        if(tab.getAttribute("name") === name) {
            if(!tab.classList.contains("active")) {
                tab.classList.add("active");
            }
        } else {
            if(tab.classList.contains("active")) {
                tab.classList.remove("active");
            }
        }
    });
    
}

function openHomepage() {
    // 页面呈现loading

    // 界面异步加载
    $.ajax({
        url: "/assets/static/homepage.html",
        type: "get",
        success: function(res) {
            let html = $(res).find("#content");
            console.log(html);
            $("main").html(html);
        }
    });
}

function openVideoDataset() {
    // 页面呈现loading

    // 界面异步加载
    $.ajax({
        url: "/assets/static/homepage.html",
        type: "get",
        success: function(res) {
            let html = $(res).find(".main-content-2");
            $("main").html(html);
        }
    });
}